package mytest.wd3;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

public class Test_8 {
    public static void main(String[] args) {

        String sql1 = "select dial_task_gid,user_gid \n" +
                "  from log_dial_task_assign_%s \n" +
                "  where (end_time is null and create_time <= 1728082799 ) or (create_time <= 1728082799  and end_time >= 1727996400) ";

        String sql2 = "select task_id,user_classify,business_id,cus_cat from t_dial_task_%s";

        String sql3 = "select task_id,user_id,call_length\n" +
                "    from t_call_log_%s \n" +
                "  where start_time >= 1727996400000 and start_time <= 1728082799000";

        String dateStr = "2024-09-30";
        DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE;
        DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyyMM");
        LocalDate date = LocalDate.parse(dateStr, formatter);
        String month0 = date.minusMonths(0).format(formatter2);
        String month1 = date.minusMonths(1).format(formatter2);
        String month2 = date.minusMonths(2).format(formatter2);
        System.out.println(month0);
        System.out.println(month1);
        System.out.println(month2);
        System.out.println(String.format(sql1, month0) + "\nunion all\n" + String.format(sql1, month1) + "\nunion all\n" + String.format(sql1, month2) + "\n");
        System.out.println(String.format(sql2, month0) + "\nunion all\n" + String.format(sql2, month1) + "\nunion all\n" + String.format(sql2, month2) + "\n");
        System.out.println(String.format(sql3, month0) + "\nunion all\n" + String.format(sql3, month1) + "\nunion all\n" + String.format(sql3, month2) + "\n");
    }
}
